﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 源文件格式化与统计
{
    public partial class Form1 : Form
    {

        string filename = null;
        public Form1()
        {

            InitializeComponent();
            
        }


        //格式化文件
        private void button1_Click(object sender, EventArgs e)
        {
            if (filename == null)
            {
                MessageBox.Show(" 请先选择文件");
            }
            else
            {
                Function function = new Function();
                function.cs_file_format(filename);
                MessageBox.Show("格式化完成");
            }
            
        }


        //统计源文件
        private void button2_Click(object sender, EventArgs e)
        {
            if (filename == null)
            {
                MessageBox.Show(" 请先选择文件");
            }
            else
            {
                Function function = new Function();
                function.cs_file_read(filename);
                MessageBox.Show("该文件共有" + function.sum_of_line + "行" + "\r\n共有" + function.sum_of_words + "个单词");
            }
            
        }

     

        //选择源文件
        private void button4_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            filename=openFileDialog1.FileName;
        }


        //统计格式化后的文件
        private void button3_Click(object sender, EventArgs e)
        {
            if (filename == null)
            {
                MessageBox.Show(" 请先选择文件");
            }
            else
            {
                Function function = new Function();
                function.cs_formatedflie_read(filename);
                foreach (KeyValuePair<string, int> word in function.Words)
                {
                    textBox1.Text+="\t"+word.Key+"\t"+word.Value+"次\r\n";
                }
            }
        }


        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
